package com.example.demo.controller;

import com.zhuozhengsoft.pageoffice.FileSaver;
import com.zhuozhengsoft.pageoffice.OpenModeType;
import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;
import com.example.demo.util.PathUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Controller
@RequestMapping(value = "/simpleWord")
public class SimpleWordController {

    //获取doc目录的磁盘路径
    private String dir = PathUtil.getDirPath() + "static/doc/";

    @RequestMapping(value="/openFile")
    public String openFile(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.setSaveFilePage("saveFile");
        poCtrl.webOpen("/doc/test.docx", OpenModeType.docNormalEdit, "张三");
        request.setAttribute("poHtmlCode", poCtrl.getHtmlCode());
        return  "simpleWord";
    }

    @RequestMapping("/saveFile")
    public void saveFile(HttpServletRequest request, HttpServletResponse response) {
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(dir + fs.getFileName());
        fs.close();
    }

}
